const url = "http://www.imooc.com/learn/348";
const http = require("http");
const cheerio = require('cheerio');

function filterHtml(html) {
    let $ = cheerio.load(html);
    $(".chapter.course-wrap").find("h3").each(function() {
        console.log($(this).text().trim());
    });
}

http.get(url, (res) => {
    res.setEncoding('utf8');
    let rawData = '';
    res.on('data', (chunk) => { rawData += chunk; });
    res.on('end', () => {
        try {
            filterHtml(rawData);
        } catch (e) {
            console.error(e.message);
        }
    });
}).on('error', (e) => {
    console.error(`Got error: ${e.message}`);
});